package com.lib.service;

import cn.hutool.core.util.StrUtil;
import com.lib.dao.RecordDao;
import com.lib.dao.ex.DaoException;
import com.lib.dao.ex.UpdateDaoException;
import com.lib.entity.Member;
import com.lib.entity.Record;
import com.lib.service.ex.EmptyArgumentException;
import com.lib.service.ex.ServiceException;
import com.lib.service.ex.UpdateServiceException;
import com.lib.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.List;

public class RecordService {
    private RecordDao recordDao = new RecordDao();
    public List<Record> GetRecordList() throws ServiceException {
        List<Record> recordList = null;
        try {
            recordList = recordDao.getRecordList();
        } catch (DaoException e) {
            throw new ServiceException("查找借阅历史失败;数据库异常"+e.getMessage(),e);
        }
        return recordList;
    }

    public void updateRecordBackDate(String id,String date) throws EmptyArgumentException, UpdateServiceException, ServiceException {
        if (StrUtil.isEmpty(id)){
            throw new EmptyArgumentException("更新借阅历史失败：id为空");
        }
        if (StrUtil.isEmpty(date)){
            throw new EmptyArgumentException("更新借阅历史失败：date为空");
        }
        try {
            recordDao.updateRecordBackDate(id,date);
        } catch (UpdateDaoException e) {
            throw new UpdateServiceException("更新借阅历史失败：数据库异常:" + e.getMessage(), e);
        } catch (DaoException e) {
            throw new ServiceException("数据库异常:" + e.getMessage(), e);
        }
    }
}
